package com.lysj.admin.master.common.spring.configuration;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.lysj.admin.master.common.CommonConstant;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Created by zk on 2019-12-25 11:29
 * @description
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    public void insertFill(MetaObject metaObject) {
        boolean hasSetter = metaObject.hasSetter(CommonConstant.CREATE_TIME_NAME);
        if (hasSetter) {
            this.setFieldValByName(CommonConstant.CREATE_TIME_NAME, new Date(), metaObject);
        }

    }

    public void updateFill(MetaObject metaObject) {
        boolean hasSetter = metaObject.hasSetter(CommonConstant.UPDATE_TIME_NAME);
        if (hasSetter) {
            this.setFieldValByName(CommonConstant.UPDATE_TIME_NAME, new Date(), metaObject);
        }
    }
}
